//----------------------------------------------------------------------
//	Copyright (C) 2010 Matias N. Goldberg ("dark_sylinc")
//
//  This is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this.  If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------

#ifndef __AnimationPanel__
#define __AnimationPanel__

/**
@file
Subclass of wxAnimationPanel, which is generated by wxFormBuilder.
*/

#include "wxOgreMeshViewerMainFrame.h"
#include "OgrePrerequisites.h"
#include <OgreColourValue.h>

namespace Ogre
{
	class MovableText;
}

/** Implementing wxAnimationPanel */
class AnimationPanel : public wxAnimationPanel
{
	struct VisualBone
	{
		Ogre::Entity		*entity;
		Ogre::MovableText	*text;
		Ogre::TagPoint		*tagNode;
	};
	struct VisualLink
	{
		VisualBone		visualBone;
		Ogre::Bone		*linkedChild;
	};

	size_t					m_entitiesId;
	Ogre::Entity			*m_loadedEntity;
	Ogre::SceneManager		*m_sceneManager;

	Ogre::AnimationState	*m_currentAnimationState;
	bool					m_playAnimation; //True if our parent should play our current animation
	float					m_animationRate;

	float					m_visulBoneSize;
	std::vector<VisualBone> m_visualBones;
	std::vector<VisualLink> m_visualLinks;

	VisualBone				m_axisOnBone;
	Ogre::ColourValue		m_boneNameColour;

	void createBoneTip( Ogre::Bone *parentBone );
	void updateBoneTips();

	void removeAxisFromBone();
protected:
	// Handlers for wxAnimationPanel events.
	void OnChangedAnimationName( wxCommandEvent& event );
	void OnAnimationChangeTime( wxCommandEvent& event );
	void OnAnimationChangeTimeScroll( wxScrollEvent& event );
	void OnButtonPlaybackSkelAnim( wxCommandEvent& event );
	void OnAnimationRateChange( wxCommandEvent& event );
	void OnLoopAnimation( wxCommandEvent& event );
	void OnRadioInterpolationMode( wxCommandEvent& event );
	void OnBoneSizeChange( wxScrollEvent& event );
	void OnNodeTrackSelect( wxTreeEvent& event );
	
public:
	/** Constructor */
	AnimationPanel( wxWindow* parent, Ogre::SceneManager *sceneManager );

	void meshLoaded( Ogre::Entity *meshEntity );
	void meshUnload();

	bool getPlayAnimation() const { return m_playAnimation; }
	float getAnimationRate() const { return m_animationRate; }
	Ogre::AnimationState* getCurrentAnimationState() const { return m_currentAnimationState; }

	void timeUpdated();

	//Show/hide bones
	void showBones( bool withNames );
	void hideBones();
	bool isShowingBones() const { return !m_visualBones.empty() || !m_visualLinks.empty(); }

	void setBoneNameColour( const Ogre::ColourValue& cv )	{ m_boneNameColour = cv;
																m_boneNameColour.a = 1.0f; }
	const Ogre::ColourValue& getBoneNameColour() const		{ return m_boneNameColour; }
};

#endif // __AnimationPanel__
